package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.AuditBean;
import com.xoms.admin.model.ProAuditBean;
import com.xoms.admin.persist.dao.ProAuditDao;
import com.xoms.util.StringUtil;

/**
 * 商品审核dao实现层
 * @author chengl
 *
 */
@Repository
public class ProAuditImpl extends BaseImpl implements ProAuditDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProAuditMapper";
	
	@Override
	public int insert(AuditBean audit) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", audit);
		
	}
	
	@Override
	public int selectCount(int type, String startTime, String endTime, String accid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("type", type);
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(accid)) {
			params.put("accid", accid);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	
	}

	@Override
	public List<ProAuditBean> selectList(int type, int page, int pageSize, String startTime, String endTime, String accid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		params.put("type", type);
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(accid)) {
			params.put("accid", accid);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public ProAuditBean selectOneById(String aid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", aid);
	}

	@Override
	public int update(ProAuditBean audit) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", audit);
	}
	
	@Override
	public String selectMaxAuditNoInYear(int type) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectMaxAuditNoInYear", type);
	}

	
}
